import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

export default defineConfig({
  plugins: [vue()],
  base: process.env.VITE_APP_ENV === 'production' ? '/盼寻密友/' : '/',
  root: path.resolve(__dirname, './'),
  server: {
    port: 9501,
    host: '0.0.0.0',
    open: true,
    overlay: {
      warnings: false,
      errors: true
    },
    proxy: {
      '/dev-api': {
        target: 'http://113.44.189.152:8888',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/dev-api/, '')
      },
      '/api': {
        target: 'http://113.44.189.152:8090',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  },
  resolve: {
    alias: {
      // 定义路径别名
      '@': path.resolve(__dirname, './src'), // 别名 '@' 指向 'src' 目录
      // 可以根据需要添加更多别名
      // 'components': path.resolve(__dirname, './src/components'),
      // 'views': path.resolve(__dirname, './src/views')
    }
  },
  define: {
    'import.meta.env': process.env
  },
  build: {
    outDir: 'dist',
    assetsDir: 'assets',
    sourcemap: false,
    rollupOptions: {
      output: {
        chunkFileNames: 'js/[name]-[hash].js',
        entryFileNames: 'js/[name]-[hash].js',
        assetFileNames: '[ext]/[name]-[hash].[ext]'
      }
    },
    // 打包时不打印日志
    logLevel: 'silent'
  }
})